package com.atguigu.myjuc.demo;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * Callable 和 FutureTask
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyThread myThread = new MyThread();
        FutureTask<String> task = new FutureTask<>(myThread);
//        FutureTask<String> task1 = new FutureTask<>(myThread);
        new Thread(task,"A").start();
//        new Thread(task1,"B").start();

        System.out.println(Thread.currentThread().getName()+"\t"+"over");

        System.out.println(task.get());//放最最后执行
    }
}

class MyThread implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"\t"+"----come in");
        //暂停亳秒
        try { TimeUnit.SECONDS.sleep(3); } catch (Exception e) { e.printStackTrace(); }
        return "Callable";
    }
}
